import 'package:flutter_admin/utils/utils.dart';
import 'package:quiver/strings.dart';

class SaleInquiryForm {
  String? id;
  String? state;
  String? inquiryNo;
  String? partnerId;
  String? partnerName;
  String? deptId;
  String? deptName;
  String? phone;
  String? email;
  String? companyId;
  String? companyName;
  String? projectName;
  String? customerNature;
  String? paymentMethod;
  String? arrivalPlace;
  String? isTargetprice;
  String? createUid;
  String? userId;
  String? userName;
  String? createDate;
  String? name;
  String? comment;
  String? createDateStart;
  String? createDateEnd;
  String? sum;
  // 新增字段
  String? currency; //报价币种
  num? exchangeRate; //下单汇率
  num? taxRate; //税率
  num? profitMargin; //利润率
  num? trafficExpense; //运输费用（元）
  num? oceanFreight; //海运费/空运费（元）
  num? transportationInsurance; //运输保险（元）
  num? guaranteeFee; //保函费用（元）
  num? heatTreatment; //熏蒸/热处理费（元）
  num? brokerageFee; //报检代理费（元）
  num? COOFG; //普惠制产地证（元）
  num? letterOfCredit; //信用证费用（元）
  num? experimentalExpenses; //试验费（元）
  num? notarialFees; //认证、公证费（元）
  num? commission; //佣金（元）
  num? factoryInspection; //厂验（元）
  num? financing; //融资费用（元）
  num? creditInsurance; //信用保险（元）
  num? constructionServiceFee; //施工服务费（元）
  num? other; //其他费（元）
  num? surveyReport; //资信调查报告费（元）
  num? amountTotal; //费用合计（元）
  num? grossProfit; //毛利润（元）
  String? content; //产品描述

  SaleInquiryForm({
    this.id,
    this.state,
    this.inquiryNo,
    this.partnerId,
    this.partnerName,
    this.deptId,
    this.deptName,
    this.phone,
    this.email,
    this.companyId,
    this.companyName,
    this.projectName,
    this.customerNature,
    this.paymentMethod,
    this.arrivalPlace,
    this.isTargetprice,
    this.createUid,
    this.userId,
    this.userName,
    this.createDate,
    this.name,
    this.comment,
    this.createDateStart,
    this.createDateEnd,
    this.sum,
    this.currency, //报价币种
    this.exchangeRate, //下单汇率
    this.taxRate, //税率
    this.profitMargin, //利润率
    this.trafficExpense, //运输费用（元）
    this.oceanFreight, //海运费/空运费（元）
    this.transportationInsurance, //运输保险（元）
    this.guaranteeFee, //保函费用（元）
    this.heatTreatment, //熏蒸/热处理费（元）
    this.brokerageFee, //报检代理费（元）
    this.COOFG, //普惠制产地证（元）
    this.letterOfCredit,
    this.experimentalExpenses, //试验费（元）
    this.notarialFees, //认证、公证费（元）
    this.commission, //佣金（元）
    this.factoryInspection, //厂验（元）
    this.financing, //融资费用（元）
    this.creditInsurance, //信用保险（元）
    this.constructionServiceFee, //施工服务费（元）
    this.other, //其他费（元）
    this.surveyReport, //资信调查报告费（元）
    this.amountTotal, //费用合计
    this.grossProfit, //毛利润
    this.content, //产品描述
  });

  SaleInquiryForm copyWith({
    String? id,
    String? state,
    String? inquiryNo,
    String? partnerId,
    String? phone,
    String? email,
    String? companyId,
    String? projectName,
    String? customerNature,
    String? paymentMethod,
    String? arrivalPlace,
    String? isTargetprice,
    String? createDate,
  }) {
    return new SaleInquiryForm(
      id: id ?? this.id,
      state: state ?? this.state,
      inquiryNo: inquiryNo ?? this.inquiryNo,
      partnerId: partnerId ?? this.partnerId,
      phone: phone ?? this.phone,
      email: email ?? this.email,
      companyId: companyId ?? this.companyId,
      projectName: projectName ?? this.projectName,
      customerNature: customerNature ?? this.customerNature,
      paymentMethod: paymentMethod ?? this.paymentMethod,
      arrivalPlace: arrivalPlace ?? this.arrivalPlace,
      isTargetprice: isTargetprice ?? this.isTargetprice,
      createDate: createDate ?? this.createDate,
    );
  }

  @override
  String toString() {
    return '''SaleInquiryForm{
      id: id,
      state: state,
      inquiryNo: inquiryNo,
      partnerId: partnerId,
      phone: phone,
      email: email,
      companyId: companyId,
      projectName: projectName,
      customerNature: customerNature,
      paymentMethod: paymentMethod,
      arrivalPlace: arrivalPlace,
      isTargetprice: isTargetprice,
      createDate: createDate,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is SaleInquiryForm &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          state == other.state &&
          inquiryNo == other.inquiryNo &&
          partnerId == other.partnerId &&
          phone == other.phone &&
          email == other.email &&
          companyId == other.companyId &&
          projectName == other.projectName &&
          customerNature == other.customerNature &&
          paymentMethod == other.paymentMethod &&
          arrivalPlace == other.arrivalPlace &&
          isTargetprice == other.isTargetprice &&
          createDate == other.createDate);

  factory SaleInquiryForm.fromMap(Map<String, dynamic> map) {
    return new SaleInquiryForm(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      state: map['state'] != false ? map['state'].toString() as String? : "",
      inquiryNo: map['inquiry_no'] != false
          ? map['inquiry_no'].toString() as String?
          : "",
      partnerId: map['partner_id'] != false
          ? map['partner_id'][0].toString() as String?
          : "",
      partnerName: map['partner_id'] != false
          ? map['partner_id'][1].toString() as String?
          : "",
      deptId: map['dept_id'] != false
          ? map['dept_id'][0].toString() as String?
          : "",
      deptName: map['dept_id'] != false
          ? map['dept_id'][1].toString() as String?
          : "",
      phone: map['phone'] != false ? map['phone'].toString() as String? : "",
      email: map['email'] != false ? map['email'].toString() as String? : "",
      companyId: map['company_id'] != false
          ? map['company_id'][0].toString() as String?
          : "",
      companyName: map['company_id'] != false
          ? map['company_id'][1].toString() as String?
          : "",
      projectName: map['project_name'] != false
          ? map['project_name'].toString() as String?
          : "",
      customerNature: map['customer_nature'] != false
          ? map['customer_nature'].toString() as String?
          : "",
      paymentMethod: map['payment_method'] != false
          ? map['payment_method'].toString() as String?
          : "",
      arrivalPlace: map['arrival_place'] != false
          ? map['arrival_place'].toString() as String?
          : "",
      isTargetprice: map['Is_targetprice'] != false
          ? map['Is_targetprice'].toString() as String?
          : "",
      createUid: map['create_uid'] != false
          ? map['create_uid'][1].toString() as String?
          : "",
      userId: map['user_id'] != false
          ? map['user_id'][0].toString() as String?
          : "",
      userName: map['user_id'] != false
          ? map['user_id'][1].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      comment:
          map['comment'] != false ? map['comment'].toString() as String? : "",
      sum: map['sum'] != false ? map['sum'].toString() as String? : "",
      currency: map['currency'] != false
          ? map['currency'].toString() as String?
          : "", //报价币种
      exchangeRate:
          map['exchange_rate'] != false ? map['exchange_rate'] : 0, //下单汇率
      taxRate: map['tax_rate'] != false ? map['tax_rate'] : 0, //税率
      profitMargin:
          map['profit_margin'] != false ? map['profit_margin'] : 0, //利润率
      trafficExpense: map['traffic_expense'] != false
          ? map['traffic_expense']
          : 0, //运输费用（元）
      oceanFreight:
          map['ocean_freight'] != false ? map['ocean_freight'] : 0, //海运费/空运费（元）
      transportationInsurance: map['transportation_insurance'] != false
          ? map['transportation_insurance']
          : 0, //运输保险（元）
      guaranteeFee:
          map['guarantee_fee'] != false ? map['guarantee_fee'] : 0, //保函费用（元）
      heatTreatment: map['heat_treatment'] != false
          ? map['heat_treatment']
          : 0, //熏蒸/热处理费（元）
      brokerageFee:
          map['brokerage_fee'] != false ? map['brokerage_fee'] : 0, //报检代理费（元）
      COOFG: map['COOFG'] != false ? map['COOFG'] : 0, //普惠制产地证（元）
      letterOfCredit: map['letter_of_credit'] != false
          ? map['letter_of_credit']
          : 0, //信用证费用（元）
      experimentalExpenses: map['experimental_expenses'] != false
          ? map['experimental_expenses']
          : 0, //试验费（元）
      notarialFees:
          map['notarial_fees'] != false ? map['notarial_fees'] : 0, //认证、公证费（元）
      commission: map['commission'] != false ? map['commission'] : 0, //佣金（元）
      factoryInspection: map['factory_inspection'] != false
          ? map['factory_inspection']
          : 0, //厂验（元）
      financing: map['financing'] != false ? map['financing'] : 0, //融资费用（元）
      creditInsurance: map['credit_insurance'] != false
          ? map['credit_insurance']
          : 0, //信用保险（元）
      constructionServiceFee: map['construction_service_fee'] != false
          ? map['construction_service_fee']
          : 0, //施工服务费（元）
      other: map['other'] != false ? map['other'] : 0, //其他费（元）
      surveyReport:
          map['survey_report'] != false ? map['survey_report'] : 0, //资信调查报告费（元）
      amountTotal:
          map['amount_total'] != false ? map['amount_total'] : 0, //费用合计（元）
      grossProfit:
          map['gross_profit'] != false ? map['gross_profit'] : 0, //毛利润（元）
      content:
          map['content'] != false ? map['content'].toString() : '', //毛利润（元）
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'state': this.state == '1'
          ? '报价'
          : this.state == '0'
              ? '询价'
              : '',
      'inquiryNo': this.inquiryNo,
      'companyName': this.companyName,
      'userName': this.userName,
      'deptName': this.deptName,
      'phone': this.phone,
      'email': this.email,
      'companyId': this.companyId,
      'projectName': this.projectName,
      'customerNature': this.customerNature,
      'paymentMethod': this.paymentMethod,
      'arrivalPlace': this.arrivalPlace,
      'isTargetprice': this.isTargetprice == '1'
          ? '是'
          : this.isTargetprice == '0'
              ? '否'
              : '',
      'createUid': this.createUid,
      'createDate': this.createDate,
      'amountTotal': this.amountTotal,
      'grossProfit': this.grossProfit,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.inquiryNo != null && this.inquiryNo != '')
        ['inquiry_no', '=', this.inquiryNo],
      if (this.partnerName != null && this.partnerName != '')
        ['partner', 'like', '%${this.partnerName}%'],
      if (this.userName != null && this.userName != '')
        ['user', 'like', '%${this.userName}%'],
      if (this.name != null && this.name != '')
        ['product', 'like', '%${this.name}%'],
      if (this.state != null && this.state != '') ['state', '=', this.state],
      if (this.createDateStart != null && this.createDateStart != '')
        [
          'create_date',
          '>=',
          Utils.timeUTC(this.createDateStart! + " 00:00:00", isToBeijing: false)
        ],
      if (this.createDateEnd != null && this.createDateEnd != '')
        [
          'create_date',
          '<=',
          Utils.timeUTC(this.createDateEnd! + " 23:59:59", isToBeijing: false)
        ],
    ] as List;
    // if (list.length == 0) {
    //   list.add(['id', '!=', null]);
    // }
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'state': this.state,
      'inquiry_no': this.inquiryNo,
      'partner_id': int.parse(this.partnerId!),
      'dept_id': int.parse(this.deptId!),
      'phone': this.phone,
      'email': this.email,
      'company_id': int.parse(this.companyId!),
      'project_name': this.projectName,
      'customer_nature': this.customerNature,
      'payment_method': this.paymentMethod,
      'Is_targetprice': this.isTargetprice,
      'arrival_place': this.arrivalPlace,
      'user_id': int.parse(this.userId!),
      'comment': this.comment,
      'currency': this.currency, //报价币种
      'exchange_rate': this.exchangeRate, //下单汇率
      'tax_rate': this.taxRate, //税率
      'profit_margin': this.profitMargin, //利润率
      'traffic_expense': this.trafficExpense, //运输费用（元）
      'ocean_freight': this.oceanFreight, //海运费/空运费（元）
      'transportation_insurance': this.transportationInsurance, //运输保险（元）
      'guarantee_fee': this.guaranteeFee, //保函费用（元）
      'heat_treatment': this.heatTreatment, //熏蒸/热处理费（元）
      'brokerage_fee': this.brokerageFee, //报检代理费（元）
      'COOFG': this.COOFG, //普惠制产地证（元）
      'letter_of_credit': this.letterOfCredit,
      'experimental_expenses': this.experimentalExpenses, //试验费（元）
      'notarial_fees': this.notarialFees, //认证、公证费（元）
      'commission': this.commission, //佣金（元）
      'factory_inspection': this.factoryInspection, //厂验（元）
      'financing': this.financing, //融资费用（元）
      'credit_insurance': this.creditInsurance, //信用保险（元）
      'construction_service_fee': this.constructionServiceFee, //施工服务费（元）
      'other': this.other, //其他费（元）
      'survey_report': this.surveyReport, //资信调查报告费（元）
      'amount_total': this.amountTotal,
      'gross_profit': this.grossProfit,
      'content': this.content,
    } as Map<String, dynamic>;
  }

  Map<String, dynamic> toOdooSavePriceFinished() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'state': '2',
    } as Map<String, dynamic>;
  }
//</editor-fold>

}
